// pages/curriculum/course/course.js

const api = require('../../../utils/api').apis;
Page({

  /**
   * 页面的初始数据
   */
  data: {
    useris:'',
    vipis:"",
    userInfo:{
      userType:'user'
    },
    userType:'user',
    curriculumActivityDTOis:'',
    video:{},
    replace:[],
    hiddena:true,
    id:Number,
    isCollect:false,
    isFree:false,
    vipIsFree:false,
    isBuy:true,
    num:0,
    key:0,
    message:{},
    bolist:{},
    bolistis:true,
    catedtois:true,
    catedto:{},
    titlelist:[],
    collectimg:'/curriculum/images/shouicon.png',
    collectimg1:'/curriculum/images/shouicon01.png',
    controls:false,
    recommend:{},
    classeslist:{},
    classeslist1:{},
    curriculumHourDtoList:{},
    Classification:'',
    pageNo:1,
    total:0,
    list:{},
    descriptionImgUrl:'',
    title:[
      {
        name:'介绍'
      },{
        name:'目录'
      },{
        name:'推荐'
      }
    ],
    countdown: {
      day: "",
      hour: "",
      minute: "",
      second: "",
    },
    currentPriceis:true,
    currentPricenum:0,
    activityTypeis:0,
    secIsEndis:true,
    insertBargainingis:0,
    name:'',
    remark:'',
    timer:null,
    
    animationData:'',
    showModalStatus:'',
    series:{},
    pages: 1,
    pageNo: 1,
    recommendList: null,
    dataArr: [],
    industryId: 0,


    nowTime:''
  },
  // 证书点击
  btnimg(e){
    let id = e.currentTarget.dataset.id
    wx.navigateTo({
      url: '/home/pages/index_zhengshu_detail/index?id='+id,
    })
  },
  hang(e){
    let id = e.currentTarget.dataset.id
    console.log(id)
    this.setData({
      id:id
    })
    wx.navigateTo({
      url: '/curriculum/pages/course/index?id='+id,
    })
    // this.getqueryCurriculumById()
  },
  // 观看视频
  changeVideo(e){
    console.log(e.currentTarget.dataset)
    let recommendId = e.currentTarget.dataset.recommendid
    let classId = e.currentTarget.dataset.classid
    let isWatch = e.currentTarget.dataset.iswatch
    let isBuy = this.data.message.isBuy
    let is = e.currentTarget.dataset.is
    if(is){
      console.log(this.data.classeslist)
      if(this.data.classeslist == null || this.data.classeslist.length == 0){
        wx.showToast({
          title: '系统错误，请在我的板块中进行反馈',
          icon:'none'
        })
      } else{
        recommendId = this.data.classeslist[0].id
        classId = this.data.classeslist[0].curriculumHourDtoList[0].id
        console.log(recommendId,classId,isWatch)
        if(isWatch == 'yes' || isBuy == 'yes'){
          wx.navigateTo({
            url: '/activity/pages/class/index?id='+this.data.id+'&recommendId='+recommendId+'&classId='+classId+'&net='+this.data.net,
          })
        } else{
          this.chang()
        }
      }
    }else{
          console.log(recommendId,classId,isWatch)
      if(isWatch == 'yes' || isBuy == 'yes'){
        wx.navigateTo({
          url: '/activity/pages/class/index?id='+this.data.id+'&recommendId='+recommendId+'&classId='+classId+'&net='+this.data.net,
        })
      } else{
        this.chang()
      }

    }

    
  },
  // id系列课获取列表
  getQueryLearnWay(){
    api.getQueryLearnWay({
      id:this.data.id
    }).then(res=>{
      console.log(res.data)

      this.setData({
        series:res.data
      })
    })
  },
  // 立即报名
  goBuyPage() {
    var _this = this
    if(this.data.name == ''){
      wx.showToast({
        title: '请输入您的姓名',
        icon: 'none',
      })
    } else if(this.remark == ''){
      wx.showToast({
        title: '请输入您的备注',
        icon: 'none',
      })
    }else{
      console.log(this.data.message.isFree,this.data.message.vipIsFree,this.data.userInfo.userType)
      if((this.data.message.isFree == 'userFree' && this.data.userInfo.userType == 'user') 
      || (this.data.message.vipIsFree == 'vipFree' && this.data.userInfo.userType == 'vip')
      || (this.data.message.isFree == 'userFree' && this.data.message.vipIsFree == 'vipFree')
      ){
        console.log('免费')
        api.orderPayMoneyByOrder({
          // 课程类型（线下：offline，线上：online，直播：live）
          courseClassification: 'offline',
          // 课程id
          courseId: this.data.id,
          // 优惠卷id (不传为null，则未使用优惠卷)
          // couponsId: null,
          // 是否使用余额， yes使用，no不使用
          // 上级分销用户Id(非必传）
          // invitationUser: null,
          name: this.data.name,
          remark: this.data.remark,
        }).then(res => {
          _this.hideModal()
          console.log(res)
          _this.getqueryCurriculumById()
          wx.navigateTo({
            url: '/curriculum/pages/inform/index?coupon=' + this.data.message.curriculumName + '&id=' + this.data.id,
          })
        })
      } else{
        console.log('不免费')
        var id = _this.data.id;
        var Classification = _this.data.message.curriculumForm;
        var Xd_token = wx.getStorageSync('Xd_Token');
        if (Xd_token) {
          console.log("已登录");
            console.log("小程序");
            wx.navigateTo({
              url: '/curriculum/pages/purchase/index?id='+_this.data.id+'&classification='+Classification+'&name='+_this.data.name+'&remark='+_this.data.remark,
            })
        } else {
          wx.navigateTo({
            url: '/login/pages/login/index?id='+_this.data.id,
          })
        }
      }
    }
  },
  signUpNow(){
    var token=wx.getStorageSync('Xd_Token');
    if(token==''||token==null||token==undefined){
      // this.getUrl()
      wx.navigateTo({
        url: '/login/pages/login/index?id='+this.data.id,
      })
      return
    }
    this.showModal()
    let number = wx.getStorageSync('userNumber')
    console.log(number)
    this.setData({
      number:number
    })
  },
      /*显示*/
        showModal: function() {
        console.log('aa')
              var animation = wx.createAnimation({
                  duration: 200,
                  timingFunction: "linear",
                  delay: 0
              })
              this.animation = animation
              animation.translateY(300).step()
              this.setData({
                  animationData: animation.export(),
                  showModalStatus: true
              })
              setTimeout(function() {
                  animation.translateY(0).step()
                  this.setData({
                      animationData: animation.export()
                  })
              }.bind(this), 200)
            },
            hideModal: function() {
              
                var animation = wx.createAnimation({
                    duration: 200,
                    timingFunction: "linear",
                    delay: 0
                })
                this.animation = animation
                animation.translateY(300).step()
                this.setData({
                    animationData: animation.export(),
                })
                setTimeout(function() {
                    animation.translateY(0).step()
                    this.setData({
                        animationData: animation.export(),
                        showModalStatus: false
                    })
                }.bind(this), 200)
            },
  // 购买
  chang(e) {
    
    if(this.data.classeslist == null || this.data.classeslist.length == 0){
      wx.showToast({
        title: '系统错误，请在我的板块中进行反馈',
        icon:'none'
      })
    } else{
    var isOriginalPrice = e ? e.currentTarget.dataset.type :'no'
    if(isOriginalPrice == undefined){
      isOriginalPrice = 'no'
    }
    console.log('iiiiiiiiiiiiiiiiiiiiiiiiiiiii',isOriginalPrice)
    var id = this.data.id;
    var Classification = this.data.message.curriculumForm;
    var Xd_token = wx.getStorageSync('Xd_Token');
    if (Xd_token) {
      console.log("已登录");
        console.log("小程序");
        wx.navigateTo({
          url: '/curriculum/pages/purchase/index?id='+this.data.id+'&classification='+Classification+'&name='+this.data.name+'&remark='+this.data.remark+'&isOriginalPrice='+isOriginalPrice,
        })
    } else {
      wx.navigateTo({
        url: '/login/pages/login/index?id='+this.data.id,
      })
    }
    }
  },
  // 立即参与事件
  insertBargaining() {
    console.log('立即参与')
    if(this.data.insertBargainingis == 0){

    console.log("参加活动");
    var Xd_token = wx.getStorageSync('Xd_Token')
    var id = this.data.id
    if (Xd_token) {
      this.insertBargainingis = 1
      api.bargainingInsertBargaining({
          curriculumId: id,
          price: this.data.message.price,
        })
        .then((res) => {
          if (res.success) {
            this.bargain();
          }
        });
    } else {
      wx.navigateTo({
        url: '/login/pages/login/index?id='+this.data.id,
      })
    }
    }
  },
      // 砍价
      bargain() {
        console.log("aaaa");
        var Xd_token = wx.getStorageSync('Xd_Token')
        if (Xd_token) {
          var price = this.data.message.price;
          var id = this.data.id;
          var Classification = this.data.message.curriculumForm;
          console.log("小程序",Classification);
          wx.navigateTo({
            url: '/activity/pages/kan_price/index?curriculumId='+this.data.id+'&price='+price+'&classification='+Classification,
          })
          this.getqueryCurriculumById()
        } else {
          wx.navigateTo({
            url: '/login/pages/login/index?id='+this.data.id,
          })
        }
      },
  // 砍价
  gitcurriculumActivityDTO(){
    console.log(this.data.message.curriculumActivityDTO)
    if(this.data.message.curriculumActivityDTO != null){
      var _this = this
      if (_this.data.message.curriculumActivityDTO.activityType == "bargaining") {
        console.log("开始砍价aaaaaaaaaaaaaaaaa");
        // 判断是否已开始砍价
        let currentPrice = _this.data.message.curriculumActivityDTO.currentPrice
          ? _this.data.message.curriculumActivityDTO.currentPrice
          : null;
        if (currentPrice == null) {
          console.log("没有砍价");
          _this.setData({
            currentPriceis:true
          })
        } else {
          _this.setData({
            currentPriceis:false
          })
          console.log("已开始砍价");
          if (currentPrice ==_this.data.message.price -_this.data.message.curriculumActivityDTO.bargainingPrice) {
            // 已砍价成功
            console.log("已砍价成功");
            _this.setData({
              currentPriceis:true
            })
          }
          console.log("aaa");
        }
        let price = _this.data.message.price? _this.data.message.price : 0;
        let pris = _this.data.message.price - currentPrice;
        var num = pris / (_this.data.message.price - _this.data.message.curriculumActivityDTO.bargainingPrice);
        console.log(pris + "1111111111111111111111111111111111111111111");
        console.log(num + "1111111111111111111111111111111111111111111");
        _this.setData({
          currentPricenum:num * 100 + "%"
        })
        // _this.currentPricenum = num * 100 + "%";
      } else {
        console.log( _this.data.message.curriculumActivityDTO.endTime,new Date())
        var endTime = new Date( _this.data.message.curriculumActivityDTO.endTime.replace(/-/g,'/')).getTime();

        var nowTime = new Date().getTime();
        console.log(nowTime, endTime)
        _this.startCountdown(nowTime, endTime);
        console.log("开始秒杀");
        if (_this.data.message.curriculumActivityDTO.secIsEnd == "no") {
          console.log("秒杀开始");
          _this.setData({
            secIsEndis:true
          })
        } else {
          console.log("秒杀抢光");
          _this.setData({
            secIsEndis:false
          })
        }
        _this.setData({
          activityTypeis:1
        })
      }
    }
  },
      // 砍价
  // 计算倒计时
  startCountdown: function (serverTime, endTime) {
    var that = this;
    // serverTime = new Date(serverTime);
    var millisecond = endTime - serverTime;
    // console.log(serverTime,endTime)
    // console.log(millisecond)
    that.data.timer = setInterval(function () {
      // console.log('循环中');
      millisecond -= 1000;
      if (millisecond <= 0) {
        clearInterval(that.data.timer);
        that.setData({
          countdown: {
            day: '00',
            hour: '00',
            minute: '00',
            second: '00'
          },
          cancel: true,
          failMask:false,
        });
        return;
      }
      
      that.transformRemainTime(millisecond);
    }, 1000);
  },
  // 剩余时间(毫秒)处理转换时间
  transformRemainTime: function (millisecond) {
    var that = this;
    var countdownObj = that.data.countdown;
    // 秒数
    var seconds = Math.floor(millisecond / 1000);
    // 天数
    countdownObj.day = that.formatTime(Math.floor(seconds / 3600 / 24));
    // 小时
    countdownObj.hour = that.formatTime(Math.floor(seconds / 3600 % 24));
    // 分钟
    countdownObj.minute = that.formatTime(Math.floor(seconds / 60 % 60));
    // 秒
    countdownObj.second = that.formatTime(Math.floor(seconds % 60));
    that.setData({
      countdown: countdownObj
    });
    // console.log(countdownObj)
  },
  //格式化时间为2位
  formatTime: function (time) {
    if (time < 10)
      return '0' + time;
    return time;
  },
  getvideo(){
    wx.navigateTo({
      // url: '/curriculum/pages/purchase/index',
      url: '/curriculum/pages/course/index',
    })
  },
    // 获取课程视频
  getCourseVideo(index){
    let id = index
    let list = this.data.classeslist[id].curriculumHourDtoList
    // let arr = {}

    // console.log(list)
    this.setData({
      list:list
    })
  },

  // 购买路由跳转
  buypurchase(){
    var id = this.data.id
    var classification = this.data.Classification
    console.log(this.data.id)
    wx.navigateTo({
      url:'/curriculum/pages/purchase/index?id='+id+'&classification='+classification,
      success: function(res){
        console.log(res)
      },
    })
  },

  // 章节点击事件
  isOpen:function(e){
    var that = this;
    var idx = e?e.currentTarget.dataset.index:0;
    var List = that.data.classeslist;
    console.log(e)
    var curId = 0;
    for(var i = 0; i < List.length; i++ ) {
      // console.log(idx +"aaa"+i)
        if( idx == i ){
          List[i].image= !List[i].image
          List[i].hiddena = !List[i].hiddena;
          // console.log(List[i])
        } else {
          List[i].image = true;
            List[i].hiddena = false;
        } 

    }
    // console.log(List[idx].id)
    this.getCourseVideo(idx)
    this.setData({
      classeslist:List
    })
},
  // 章节点击事件
  switchbox(e){
    var id = e.currentTarget.dataset.id
    console.log(id)
  },
  // 视频点击
  bindvideo(){
    this.setData({
      controls:true
    })
  },
  // 介绍目录推荐切换点击
  changColor:function(e){
    this.setData({
      key:e.currentTarget.dataset.index,
    })
  },
  // 推荐里边的点击事件
  listbox(e){
    var id = e.currentTarget.dataset.id
    console.log(id)
    wx.navigateTo({
      url:'/curriculum/pages/course/index?id='+id,
    })
  },
  // 收藏点击
  collect:function(){
    
    if(this.data.isCollect == false){
      console.log('wei')
      api.getCollect({
        "relation":this.data.id,
        "type":"curriculum"
      }).then(res=>{
        console.log(res)
      })
      this.setData({
        isCollect:true
      })
      
    } else{
      api.cancelCollect({
        "relation":this.data.id,
        "type":"curriculum"
      }).then(res=>{
        console.log(res)
      })
      this.setData({
      isCollect:false
      })
      
    }
  },
  //阿拉伯数字转换成大写汉字// 章节大小写
  numberParseChina:function(money){
  //汉字的数字
    var cnNums = new Array('零',  "一", "二", "三", "四", "五", "六", "七", "八", "九");
    //基本单位
    var cnIntRadice = new Array('', '十', '佰', '仟');
    //对应整数部分扩展单位
    var cnIntUnits = new Array('', '万', '亿', '兆');
    //对应小数部分单位
    var cnDecUnits = new Array('角', '分', '毫', '厘');
    //整数金额时后面跟的字符
    var cnInteger = '';
    //整型完以后的单位
    var cnIntLast = '';
    //最大处理的数字
    var maxNum = 999999999999999.9999;
    //金额整数部分
    var integerNum;
    //金额小数部分
    var decimalNum;
    //输出的中文金额字符串
    var chineseStr = '';
    //分离金额后用的数组，预定义
    var parts;
    if (money == '') { return ''; }
    money = parseFloat(money);
    if (money >= maxNum) {
      //超出最大处理数字
      return '';
    }
    if (money == 0) {
      chineseStr = cnNums[0] + cnIntLast + cnInteger;
      return chineseStr;
    }
    //转换为字符串
    money = money.toString();
    if (money.indexOf('.') == -1) {
      integerNum = money;
      decimalNum = '';
    } else {
      parts = money.split('.');
      integerNum = parts[0];
      decimalNum = parts[1].substr(0, 4);
    }
    //获取整型部分转换
    if (parseInt(integerNum, 10) > 0) {
      var zeroCount = 0;
      var IntLen = integerNum.length;
      for (var i = 0; i < IntLen; i++) {
        var n = integerNum.substr(i, 1);
        var p = IntLen - i - 1;
        var q = p / 4;
        var m = p % 4;
        if (n == '0') {
          zeroCount++;
        } else {
          if (zeroCount > 0) {
            chineseStr += cnNums[0];
          }
          //归零
          zeroCount = 0;
          chineseStr += cnNums[parseInt(n)] + cnIntRadice[m];
        }
        if (m == 0 && zeroCount < 4) {
          chineseStr += cnIntUnits[q];
        }
      }
      chineseStr += cnIntLast;
    }
    //小数部分
    if (decimalNum != '') {
      var decLen = decimalNum.length;
      for (var i = 0; i < decLen; i++) {
        var n = decimalNum.substr(i, 1);
        if (n != '0') {
          chineseStr += cnNums[Number(n)] + cnDecUnits[i];
        }
      }
    }
    if (chineseStr == '') {
      chineseStr += cnNums[0] + cnIntLast + cnInteger;
    } else if (decimalNum == '') {
      chineseStr += cnInteger;
    }
    // this.setData({
    //   replace:chineseStr
    // })
    return chineseStr
    
    // return chineseStr;
  },
  onReady: function () {  //创建视频上下文对象
    this.videoContextplay = wx.createVideoContext('myVideo')
  },
  playvideo(e) {
    var videoindex = e.currentTarget.dataset.index;
    var videoid = e.currentTarget.dataset.videoid;
    that.setData({
      playIndex: videoindex,
      videoid: videoid,
      videonum: e.currentTarget.dataset.videonum,
      heightclick: parseInt(e.detail.y),
      videosrc: e.currentTarget.dataset.videosrc
    })
    this.tipsAnimation.translateY(-this.tipsheight).step();
    this.setData({
      tipsAnimation: this.tipsAnimation.export()
    })
    // 检查网络状态
    wx.getNetworkType({
      success: function (res) {
        if (res.networkType == '4g' || res.networkType == '3g' || res.networkType == '2g') {
          that.setData({
            playshow: true,
            jxplay: false,
          })
          // console.log('4G网络')
        } else if (res.networkType == "none" || res.networkType == "unknown") {
          wx.showToast({
            title: '您的网络有问题',
            icon: 'none',
            duration: 1500
          })
          // console.log('您的网络有问题')
        } else {
          var obj = 'videos[' + videoindex + '].readnum';
          that.setData({
            autoplay: true,
            [obj]: parseInt(that.data.videonum) + 1,
            jxplay: false,
            playshow: false
          })
          /* console.log('jxplay111',that.data.jxplay)*/
          // console.log("返回wifi状态111") 
        }
      }
    })
  },
  getsearchCourse(id){
    // 推荐课程
    api.searchCourse({
      id:id,
      pageNo:this.data.pageNo,
      pageSize:'8',
      isFree:'userFree'
    }).then(res=>{
      if (this.data.pageNo == 1) {
        this.setData({
          recommend: res.data.records,
          total: res.data.total
        })
      } else {
        this.setData({
          recommend: this.data.recommend.concat(res.data.records),
          total: res.data.total
        })
      }
      // console.log(res.data.records)
    })
  },
  
    // 根据课程ID查询课程详细信息
    
  getqueryCurriculumById(){
    api.searchCourseMessage({
      "id":this.data.id,
      "pageSize":""
    }).then(res=>{
    // 课程小标签
      var str = res.data.curriculum.label
      var arr = str.split(',')
      // arr.push(res.data.curriculum.curriculumTime)
      // console.log(arr)
      
    // 是否收藏
    if(res.data.curriculum.isCollect == 'yes'){
      // console.log('收藏')
      this.setData({
        isCollect:true
      })
    }
    // 是否无证书
    if(res.data.curriculum.curriculumCertificateDto){
      this.setData({
        catedtois:false
      })
    }
    // 是否免费
    if(res.data.curriculum.isFree == 'userFree'){
      // console.log('免费')
      this.setData({
        isFree:true
      })
    }
    // 是否购买
    if(res.data.curriculum.isBuy == 'no'){
      // console.log('未购买')
      this.setData({
        isBuy:false
      })
    }
    // 是否会员
    if(res.data.curriculum.vipIsFree == 'vipFree'){
      // console.log('会员免费')
      this.setData({
        vipIsFree:true
      })
    }
    // 是否有教师数据
    if(res.data.curriculum.teacherBOList.length == 0){
      this.setData({
        bolistis:false
      })
    }
  
      console.log(res.data)
      this.setData({
        descriptionImgUrl:res.data.curriculum.descriptionImgUrl,
        message:res.data.curriculum,
        bolist:res.data.curriculum.teacherBOList[0],
        catedto:res.data.curriculum.curriculumCertificateDto,
        titlelist:arr,
        Classification:res.data.curriculum.curriculumForm
      })
      if(this.data.userInfo.userType == 'user' && this.data.message.isFree == 'userFree' && this.data.message.isBuy == 'no'){
        this.setData({
          useris:true
        })
      }
      if(this.data.userInfo.userType == 'vip' && this.data.message.vipIsFree == 'vipFree' && this.data.message.isBuy == 'no'){
        this.setData({
          vipis:true
        })
      }
      if(this.data.message.curriculumActivityDTO == null ||this.data.message.curriculumActivityDTO.id == null ){
        this.setData({
          curriculumActivityDTOis:false
        })
      } else{
        console.log(this.data.message.curriculumActivityDTO)
        if(this.data.message.curriculumActivityDTO.activityType == 'bargaining'){
          wx.setNavigationBarTitle({ title: '砍价活动' })
        } else{
          wx.setNavigationBarTitle({ title: '秒杀活动' })
        }
        this.setData({
          curriculumActivityDTOis:true
        })
      }
      console.log(this.data.curriculumActivityDTOis)
      this.gitcurriculumActivityDTO()
      
    this.getRecommend()
    })
  },
  bindconfirm(e) {
    let val = e.detail.value;
    this.setData({
      name:val
    })
},
bindconfirm1(e) {
  let val = e.detail.value;
  this.setData({
    remark:val
  })
},
sendsign(){
  wx.showLoading({
    title: '报名中',
  })
   if(this.data.valname == ''){
     wx.showToast({
       title: '姓名不能为空',
       icon: 'none',
     })
   } else{
    //  api.getSendsign({
    //    recruitmentId:this.data.id,
    //    name:this.data.valname,
    //    remark:this.data.valremark
    //  }).then(res=>{
    //    if(res.success){
    //      wx.showToast({
    //        title: '报名成功',
    //      })
    //    } else{
    //      wx.showToast({
    //        icon:'none',
    //        title: '请勿重复报名',
    //      })
    //    }
    //    console.log(res)
    //    wx.hideLoading()
    //  })
     this.hideModal()
   }
   
 },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var timestamp = Date.parse(new Date());
    timestamp = this.formatTimes(timestamp);
    var id = options.id
    this.setData({
      id:options.id,
      nowTime:timestamp
    })
    console.log('秒杀',this.data.nowTime)
    var userInfo = wx.getStorageSync('userInfo') ? wx.getStorageSync('userInfo'): this.data.userInfo
    
    this.getqueryCurriculumById()
    this.setData({
      userInfo:userInfo
    })
    console.log(this.data.userInfo)
    api.getAuthorization({
      id:options.id
    }).then(res=>{
      console.log(id)
      if(res.data == null){

      } else{

        this.setData({
          video:res.data
        })
        console.log(res.data)
      }
    })
    
    // 课程目录查询课时
    api.queryClasses({
      id:options.id
    }).then(res=>{
      var arr = res.data
      var arr1 = []
      var arr2 = []
      console.log(arr)
      arr.map(item=>{
        if(item.chapterType == 'normal'){
          item.hiddena=false
          item.image=true
          item.num = ''
          var aa = []
          for (var i = 0 ;i<=arr1.length;i++){
            var j = i+1
            var replace = this.numberParseChina(j)
            aa.push(replace)
          }
          this.setData({
            replace:aa
          })
          arr1.push(item)
        } else{
          arr2.push(item)
          // item.splice()
        }
      })
      console.log('aaaaaa')
      this.gitcurriculumActivityDTO()
      this.setData({
        classeslist:arr1,
        classeslist1:arr2
      })
      this.isOpen()
    })
    

    this.getsearchCourse(id)
    // this.getCourseVideo(id)
    
    
    this.getQueryLearnWay()

    // console.log(id)
    // console.log(this.data.bolist)
  },
  changeIt(){
    this.getRecommend()
  },
  // getData() {
  //   api.recruitmentQueryRecruitmentById({
  //     id: this.data.id
  //   }).then(res => {
  //     let positionDescription=res.data.positionDescription.replace('<img ', '<img style="max-width:100%;height:auto;display:block;margin:10px 0;"') 
  //     this.setData({
  //       dataArr: res.data,
  //       positionDescription:positionDescription,
  //       industryId:res.data.industryId
  //     })
  //   this.getRecommend()
  //   })
  // },
  getRecommend() {
    api.curriculumReplaceCurriculumRecommend({
      pages: this.data.pages,
      pageSize: 5,
      pageNo: this.data.pageNo,
      industryId: this.data.message.industryId
    }).then(res => {
      console.log(res.data)
      if(res.data){
        this.setData({
          recommendList: res.data.recommendCurriculumIpage.records,
          pages: res.data.recommendCurriculumIpage.pages,
          pageNo:res.data.recommendCurriculumIpage.current
        })
      }
      console.log(this.data.recommendList)
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
   
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.getqueryCurriculumById()
    let _this=this;
    // wx.getNetworkType({
    //   success(res){
    //     var net = wx.getStorageSync('net') ? wx.getStorageSync('net'): false
    //     console.log(res.networkType)
    //     if(res.networkType == 'wifi' || net){
    //       var net = true
    //     } else{
    //       var net = false
    //     }
    //     _this.setData({
    //       net:net
    //     })
    //   }

    // })
  },
    // 证书点击
    btnimg(e){
      let id = e.currentTarget.dataset.id
      wx.navigateTo({
        url: '/home/pages/index_zhengshu_detail/index?id='+id,
      })
    },
  formatTimes(row) {
    if (!row) return '无';
    const date = new Date(row),
      year = date.getFullYear(),
      month = date.getMonth() > 9 ? date.getMonth() + 1 : `0${date.getMonth() + 1}`,
      day = date.getDate() > 9 ? date.getDate() : `0${date.getDate()}`,
      hh = date.getHours() > 9 ? date.getHours() : `0${date.getHours()}`,
      mm = date.getMinutes() > 9 ? date.getMinutes() : `0${date.getMinutes()}`,
      ss = date.getSeconds() > 9 ? date.getSeconds() : `0${date.getSeconds()}`;
    return `${year}-${month}-${day} ${hh}:${mm}:${ss}`;
  },
  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
    clearInterval(this.data.timer);
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
    clearInterval(this.data.timer);

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    // console.log('aaa')
    if(this.data.recommend.length <this.data.total){
      console.log(111)
      let page = ++this.data.pageNo
      this.setData({
        pageNo:page
      })
      this.getsearchCourse(this.data.id)
    }
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
  
})